package com.hex.liyue.giftmodule.presenter;

import com.alibaba.fastjson.JSONArray;
import com.hex.liyue.commonmodule.manager.HttpManager;
import com.hex.liyue.commonmodule.manager.UserManager;
import com.hex.liyue.commonmodule.net.ResponseListener;
import com.hex.liyue.giftmodule.bean.DiscountDetailsBean;
import com.hex.liyue.giftmodule.bean.MyGiftsResultBean;

/**
 * Created by WJ on 2016/6/24.
 */
public class MyGiftsPresenter {
    private IMyGiftsView iMyGiftsView;

    public MyGiftsPresenter(IMyGiftsView iMyGiftsView) {
        this.iMyGiftsView = iMyGiftsView;
    }

    /**
     * 获取我的礼物
     */
    public void requestGetMyGiftList() {
        iMyGiftsView.showLod("加载中...");
        HttpManager.getInstance().myGiftList(UserManager.getUserId(), new ResponseListener<MyGiftsResultBean>() {
            @Override
            public void onSuccess(MyGiftsResultBean myGiftsResultBean) {
                iMyGiftsView.closeLod();
                iMyGiftsView.setAdapter(myGiftsResultBean);
            }

            @Override
            public void onFailure(String responseresult) {
                iMyGiftsView.closeLod();
            }
        });
    }

    /**
     * 礼物折现
     */
    public void gift_discount(JSONArray gift_list) {
        iMyGiftsView.showLod("加载中...");
        HttpManager.getInstance().gift_discount(UserManager.getUserId(), gift_list, new ResponseListener<DiscountDetailsBean>() {
            @Override
            public void onSuccess(DiscountDetailsBean discountDetailsBean) {
                iMyGiftsView.closeLod();
                iMyGiftsView.startDiscountDetailsActivity(discountDetailsBean);
            }

            @Override
            public void onFailure(String responseresult) {
                iMyGiftsView.closeLod();
                iMyGiftsView.showT(responseresult);
            }
        });
    }

}
